<?php
error_reporting("E_ALL");ini_set("display_errors", 1);
header("content-Type: application/json; charset=utf-8");
include("include/function.php");
$get = !empty($_POST)?$_POST:$_GET;
$txt = !empty($get['txt'])?trim($get['txt']):'';
$volume=!empty($get['volume'])?intval($get['volume']):50;
$speed=!empty($get['speed'])?intval($get['speed']):50;
$speaker=!empty($get['speaker'])?intval($get['speaker']):33;
$pitch=!empty($get['pitch'])?intval($get['pitch']):50;
$type=!empty($get['type'])?intval($get['type']):1;
$tone=!empty($get['tone'])?intval($get['tone']):42;
$language=!empty($get['language'])?intval($get['language']):91;
$sampling_rate=!empty($get['sampling_rate'])?intval($get['sampling_rate']):816;
if(empty($txt)){exit('?txt=');}
$url  = 'https://yntts.qq.com/generateTTSURL';
$param=[
  "txt"=> $txt,
  "volume"=> $volume,
  "speed"=> $speed,
  "speaker"=> $speaker,
  "pitch"=> $pitch,
  "type"=> $type,
  "tone"=> $tone
];
$jsondata=json_encode($param, JSON_UNESCAPED_UNICODE);
$headers=[];
$headers=['Content-Type: application/json;charset=UTF-8'];
$headers[]='User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 Edg/139.0.0.0';
$res = curlget($url,$jsondata,'POST',$headers,true);
$return =json_decode($res,true);
if(empty($return)){
    $return=array('code'=>1,'msg'=>'获取失败','body'=>$res);
}else{
    if(!empty($return['session_id']))$return['mp3']='https://yntts.qq.com/tts.mp3?session_id='.$return['session_id'].'&speaker='.$speaker.'&language='.$language.'&sampling_rate='.$sampling_rate;
}
ajaxReturn($return);
?>